<?php
/**
 * Included in all pages.
 * 
 * Blocks unlogged users access unless $public = true; is declared.
 */

	// Set the include path
		
		// Online
		set_include_path('/home/a9068890/public_html/');
		
		//Ander-fijo
		set_include_path('C:/xampp/htdocs/TIMproject/');
		
		//Ander-portatil
		//set_include_path('/opt/lampp/htdocs/eclipseworkspace/TIMproject/');
		
	$common = true;

	// Starting the session
	if(!isset($_SESSION))
	{
		session_start();
	}  
	
	//Check if username is not in session but is in cookie
	if(!isset($_SESSION["username"]) && isset($_COOKIE["username"]))
	{
		// Load the session
        require 'include/class/usersession.php';
        usersession::loadSession($_COOKIE["username"]);
	}
	
	//Set the default language for new users
	if (!isset($_COOKIE["lang"]))
	{	
		setcookie("lang", "es", time()+3600);
		$_COOKIE["lang"] = "es"; // As the cookie is set for the next page load, this prevents an error the first time this page is viewed
	}
	
	//Block pages that are not public to unlogged users
	if(!isset($public) || $public==false)
	{
		if(!isset($_SESSION["username"]))
		{
			echo 'debes estar registrado';		
			exit;
		}
	}
	
	//Include the settings
	require_once 'settings.php';
	require_once 'localsettings.php';
	
	//Include the common files
	require_once 'include/lang.php';
	
	//Check if pending operations have finished (attacks, constructions...)
	include_once 'include/chronos.php';

	//Don't show errors unless developping
	error_reporting(0);
?>